﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace graduation_project.Voice_Recognition
{
    class DynamicAddXml
    {
        XmlDocument Cmdxml = null;
        public string []XmlBuffer=new string[3];
        private string[] TempBuffer = new string[3];
        string Keyxml = "E://WorkSpace//c++//graduation project//graduation project//Xml//Dynamic.xml";
        public void UpdateXml()
        {
            int i=0;
            Cmdxml = new XmlDocument();
            Cmdxml.Load(Keyxml);
            //获取所有子节点
            XmlNodeList NodeList = Cmdxml.SelectSingleNode("GRAMMAR").ChildNodes;
            foreach (XmlNode Xmln in NodeList)
            {
                XmlElement Xmle = (XmlElement)Xmln;   //强制转换类型。
                if (Xmle.GetAttribute("NAME") == "COMMAND")
                {
                    XmlNodeList KeyWords = Xmle.FirstChild.ChildNodes;
                    foreach (XmlNode KeyN in KeyWords)
                    {
                        XmlElement KeyL=(XmlElement)KeyN;
                        if (KeyL.Name == "p")
                        {
                            KeyL.InnerText = XmlBuffer[i];
                        }
                        i++;
                    }
                    break;
                }
            }
            Cmdxml.Save(Keyxml);
            MessageBox.Show("载入成功！");
        }
    }
}
